rm(list = ls())

setwd("/Users/Joan/Google Drive/UMD/Spring'16/GVPT729M Multi-level/Paper")
load("timeobama1.RData")

attach(df1)

red1  <- (obs.fw - min(obs.fw)) / (max(obs.fw) - min(obs.fw))
red2  <- (obs.bw - min(obs.bw)) / (max(obs.bw) - min(obs.bw))
red3  <- (diff - min(diff)) / (max(diff) - min(diff))
red4  <- (diff.pct - min(diff.pct)) / (max(diff.pct) - min(diff.pct))

setwd("/Users/Joan/Google Drive/Article Twitter Streams and Removal Rates/TeX")
tiff("Fig4.tif", width=1824, height=1824, pointsize=12, res=300)

par(mfrow=c(2, 2), oma = c(0,0,0,0), mar=c(4,4,1,1)) #B, L, U, R

plot(obs.fw, ylab='NºObs Stream API',xlab='Take',cex.lab=0.8, col=rgb(red1, 0.1, 0.5, 0.8), 
     cex.axis=0.1, cex=1, pch=19, xaxt = "n", yaxt = "n", line=2)
axis(2, at=c(200, 400, 600, 800), labels=c("200", "400", "600", "800"), cex.axis=0.7, tck=-0.03,
     adj=0.1)
axis(1, at=c(1, 50, 100), labels=c("1", "50", "100"), cex.axis=0.7, tck=-0.03)

plot(obs.bw, ylab='NºObs Search API', xlab='Take',cex.lab=0.8, col=rgb(red2, 0.1, 0.5, 0.8), 
     cex.axis=0.7, cex=1, pch=19, xaxt = "n", yaxt = "n", line=2)
axis(2, at=c(100, 200, 300, 400, 500, 600), labels=c("100", "200", "300", "400", "500", "600"), cex.axis=0.7, tck=-0.03)
axis(1, at=c(1, 50, 100), labels=c("1", "50", "100"), cex.axis=0.7, tck=-0.03)

plot(diff.pct, ylab='Percent Difference', xlab='Take',cex.lab=0.8, col=rgb(red4, 0.1, 0.5, 0.8), 
     cex.axis=0.7, cex=1, pch=19, xaxt = "n", yaxt = "n", line=2)
axis(2, at=c(seq(0, 0.7, 0.1)), labels=c(seq(0, 0.7, 0.1)), cex.axis=0.7, tck=-0.03)
axis(1, at=c(1, 50, 100), labels=c("1", "50", "100"), cex.axis=0.7, tck=-0.03)

plot(diff.pct~obs.fw, xlab= 'NºObs Stream API', ylab='Percent Difference', cex.lab=0.8, 
    col=rgb(red=0.1, green=0.1, blue=1.0, alpha=0.5), cex.axis=0.7, cex=1, pch=19, 
    xaxt = "n", yaxt = "n", line=2)
axis(2, at=c(seq(0, 0.7, 0.1)), labels=c(seq(0, 0.7, 0.1)), cex.axis=0.7, tck=-0.03)
axis(1, at=c(200, 400, 600, 800), labels=c(200, 400, 600, 800), cex.axis=0.7, tck=-0.03)
fit <- lm(diff.pct ~ obs.fw + I(obs.fw^2), data=df1)
lines(sort(obs.fw), fitted(fit)[order(obs.fw)], col='red', type='l', lwd=3) 

dev.off()
#plot(density(diff.pct))
